from app.extension.database.sqlalchemy import sqla_db as db
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, DateTime
from datetime import datetime


class StoreModel(db.Model):
    """商铺模型"""
    __tablename__ = 'tb_store'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,  nullable=False, unique=True, comment='商户对应的用户id')
    status = db.Column(db.Integer, comment='商铺状态: 1 没有审核 2 运行中')

    mobile = db.Column(db.String(50), comment='店铺号码')
    user_name = db.Column(db.String(50), comment='业主名')
    store_name = db.Column(db.String(50), comment='商铺名')
    img_shopkeeper_id_card_id = db.Column(db.String(50), comment='身份证')
    img_logo_id = db.Column(db.String(255), comment='商铺logo')
    img_business_license_id = db.Column(db.String(255), comment='营业执照')
    address = db.Column(db.String(255), comment='地址')
    summary = db.Column(db.String(255), comment='商铺摘要')

    create_time = db.Column(db.DateTime, default=datetime.now)
    delete_time = db.Column(db.DateTime)

    def __init__(self, data: dict, user_id, status):
        self.mobile = data.get('mobile')
        self.user_name = data.get('user_name')
        self.store_name = data.get('store_name')
        self.img_shopkeeper_id_card_id = data.get('img_shopkeeper_id_card_id')
        self.img_business_license_id = data.get('img_business_license_id')
        self.img_logo_id = data.get('img_logo_id')
        self.address = data.get('address')
        self.summary = data.get('summary')
        self.status = status
        self.user_id = user_id

    def update_status(self, status):
        self.status = status

